package com.wang.jmonkey.ca.model;

import com.wang.jmonkey.ca.handler.login.request.RequestHandlerManager;
import com.wang.jmonkey.common.constant.SecurityConstant;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.context.ApplicationContext;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description 登陆了信息
 * @Author HeJiawang
 * @Date 2021/5/11 10:36
 */
@Data
@Accessors(chain = true)
public class AuthParam {

    private String username;

    private String password;

    private String code;

    private String deviceId;

    private String oauthType;

    private String refreshToken;

    public AuthParam(HttpServletRequest request , ApplicationContext context) {
        parser(request, context);
        requestWrapper(request);
    }

    private void requestWrapper(HttpServletRequest request) {
        request.setAttribute(SecurityConstant.LoginParameter.username.getKey(), this.getUsername());
        request.setAttribute(SecurityConstant.LoginParameter.password.getKey(), this.getPassword());
        request.setAttribute(SecurityConstant.LoginParameter.code.getKey(), this.getCode());
        request.setAttribute(SecurityConstant.LoginParameter.deviceId.getKey(), this.getDeviceId());
        request.setAttribute(SecurityConstant.LoginParameter.oauthType.getKey(), this.getOauthType());
        request.setAttribute(SecurityConstant.LoginParameter.refreshToken.getKey(), this.getRefreshToken());
    }

    private void parser(HttpServletRequest request , ApplicationContext context) {
        RequestHandlerManager manager = context.getBean(RequestHandlerManager.class);
        manager.handler(request, this, manager);
    }
}
